export type EnvType =
  | 'app'
  | 'wx'
  | 'ios'
  | 'android'
  | 'iphone'
  | 'mobile'
/** 判断当前浏览器所在的宿主环境 */
const isEnv = (env: EnvType, userAgent?: string): boolean => {
  // 非浏览器环境返回 null
  if (typeof window === 'undefined' && !userAgent) {
    return false
  }
  const UA = (userAgent ?? navigator.userAgent).toUpperCase()
  if (env === 'mobile') {
    return /Android|webOS|iPhone|iPad/i.test(UA)
  }
  let specialStr = ''
  switch (env) {
    case 'app':
      specialStr = 'GOGOALER'
      break
    case 'wx':
      specialStr = 'MICROMESSENGER'
      break
    case 'iphone':
      specialStr = 'IPHONE'
      break
    case 'android':
      specialStr = 'ANDROID'
      break
    case 'ios':
      specialStr = 'MAC OS X'
      break
    default:
      return false
  }
  return UA.includes(specialStr)
}
/** 是否app内*/
const isApp = () => isEnv('app')
/** 判断是否是微信 */
const isWX = () => isEnv('wx')
/** Android */
const isAndroid = () => isEnv('android')
/** IOS */
const isIOS = () => isEnv('ios')
/** IphoneX */
const isIphoneX = () => {
  return isEnv('ios') && window.screen.height === 812 && window.screen.width === 375
}
/** 是否移动端*/
const isMobile = () => isEnv('mobile')
export {
    isEnv,
    isApp,
    isWX,
    isIOS,
    isIphoneX,
    isAndroid,
    isMobile
  }
  